home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / animutil / fastgfx / fg303b / manuals.arj / USER03.DOC < prev    next >
Encoding:
Text File  |  1993-10-02  |  35.5 KB  |  805 lines

  1. Chapter 3
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Initializing the
  8. Video Environment
  9.  
  10. 44   Fastgraph User's Guide
  11.  
  12.  
  13.  
  14. Overview
  15.  
  16.      Before Fastgraph can perform any text or graphics video operations, you
  17. must select a video mode in which your program will run.  An important part
  18. of this selection depends on whether your program will run in a text mode, a
  19. graphics mode, or both.  The first two sections in this chapter discuss the
  20. necessary video initialization for standard text and graphics modes, while
  21. the last section addresses the additional setup needed for SuperVGA (SVGA)
  22. graphics modes.
  23.  
  24.  
  25. Establishing a Text Mode
  26.  
  27.      When you write a program that only uses text modes, you must determine
  28. if the program will run on monochrome systems, color systems, or both.  In
  29. general, there is no reason to exclude one type of system, because the
  30. additional programming required to support both is rather trivial.
  31.  
  32.      The Fastgraph routine fg_setmode establishes a video mode and
  33. initializes Fastgraph's internal parameters for that mode.  This routine has
  34. a single integer argument whose value is a video mode number between 0 and
  35. 29.  Its value can also be -1, which tells Fastgraph to use the current video
  36. mode.  Specifying an fg_setmode argument of -1 is often useful in programs
  37. that only use text video modes.
  38.  
  39.      When you establish a text video mode, the ROM BIOS text cursor is made
  40. visible, and this is often undesirable.  The Fastgraph routine fg_cursor
  41. controls the visibility of the text cursor.  The fg_cursor routine has a
  42. single integer argument that specifies the cursor visibility.  If its value
  43. is 0, the cursor is made invisible; if its value is 1, the cursor is made
  44. visible.
  45.  
  46.      At this point, an example may help to clarify things.  The following
  47. program shows how to initialize Fastgraph for the 80-column color text mode
  48. (mode 3) and turn off the text mode cursor.  It uses two Fastgraph routines
  49. that we have not yet discussed, fg_setcolor and fg_text.  These routines will
  50. be discussed in later sections of this document.  For now, it should suffice
  51. to know the call to fg_setcolor makes subsequent text appear in white, and
  52. the call to fg_text displays the characters passed to it.
  53.  
  54.                                  Example 3-1.
  55.  
  56.                        #include <fastgraf.h>
  57.                        void main(void);
  58.  
  59.                        void main()
  60.                        {
  61.                           fg_setmode(3);
  62.                           fg_cursor(0);
  63.  
  64.                           fg_setcolor(15);
  65.                           fg_text("Hello, world.",13);
  66.                        }
  67.  
  68.                            Chapter 3:  Initializing the Video Environment   45
  69.  
  70.  
  71.      If you run example 3-1, notice the text displayed by the program appears
  72. in the upper left corner of the screen.  On the line below this, the DOS
  73. prompt appears, waiting for your next DOS command.  Furthermore, if your
  74. system uses the ANSI.SYS driver to set screen attributes (such as with
  75. Norton's SA program), you should also notice only the DOS prompt appears in
  76. the colors defined by the screen attributes -- the rest of the screen is
  77. blank.
  78.  
  79.      A more graceful return to DOS is needed.  In example 3-2, we'll use the
  80. Fastgraph routine fg_reset.  This routine erases the screen, and if the
  81. ANSI.SYS driver is loaded, fg_reset also restores any previously set screen
  82. attributes.  We've also included a call to the Fastgraph routine fg_waitkey
  83. to wait for a keystroke before exiting.  If we didn't do this, we would never
  84. see the program's output.
  85.  
  86.                                  Example 3-2.
  87.  
  88.                        #include <fastgraf.h>
  89.                        void main(void);
  90.  
  91.                        void main()
  92.                        {
  93.                           fg_setmode(3);
  94.                           fg_cursor(0);
  95.  
  96.                           fg_setcolor(15);
  97.                           fg_text("Hello, world.",13);
  98.                           fg_waitkey();
  99.  
  100.                           fg_reset();
  101.                        }
  102.  
  103.      Since examples 3-1 and 3-2 specifically used video mode 3, they would
  104. not work on a monochrome system.  Ideally, we'd like to use fg_setmode(3) for
  105. color systems and fg_setmode(7) for monochrome systems.  To do this, we need
  106. a way to determine whether the program is being run on a color system or on a
  107. monochrome system.  The next example illustrates an easy way to do this.
  108.  
  109.      Example 3-3 uses the Fastgraph routine fg_testmode to determine if the
  110. user's system will support the video mode number specified as its first
  111. argument (the second argument is the number of video pages required, which
  112. will be 1 for all examples in this section).  The fg_testmode routine returns
  113. a value of 1 (as its function value) if the requested video mode can be used,
  114. and it returns 0 if not.  The program first sees if an 80-column color text
  115. mode is available (mode 3), and if so, it selects that mode.  If the color
  116. mode is not available, it checks if the monochrome text mode is available
  117. (mode 7), and if so, it chooses the monochrome mode.  If neither mode is
  118. available, then the program assumes the user's system has a 40-column
  119. display, issues a message indicating the program requires an 80-column
  120. display, and then exits.
  121.  
  122.                                  Example 3-3.
  123.  
  124.                    #include <fastgraf.h>
  125.                    #include <stdio.h>
  126.                    #include <stdlib.h>
  127. 46   Fastgraph User's Guide
  128.  
  129.  
  130.                    void main(void);
  131.  
  132.                    void main()
  133.                    {
  134.                       int old_mode;
  135.  
  136.                       old_mode = fg_getmode();
  137.  
  138.                       if (fg_testmode(3,1))
  139.                          fg_setmode(3);
  140.                       else if (fg_testmode(7,1))
  141.                          fg_setmode(7);
  142.                       else {
  143.                          printf("This program requires\n");
  144.                          printf("an 80-column display.\n");
  145.                          exit(1);
  146.                          }
  147.  
  148.                       fg_cursor(0);
  149.  
  150.                       fg_setcolor(15);
  151.                       fg_text("Hello, world.",13);
  152.                       fg_waitkey();
  153.  
  154.                       fg_setmode(old_mode);
  155.                       fg_reset();
  156.                    }
  157.  
  158.      Example 3-3 also illustrates another useful procedure.  It is
  159. recommended, especially in graphics modes, to restore the original video mode
  160. and screen attributes before a program returns to DOS.  We've already seen
  161. how the fg_reset routine restores the screen attributes, but how do we
  162. restore the original video mode?  The Fastgraph routine fg_getmode returns
  163. the current video mode as its function value.  If we call fg_getmode before
  164. calling fg_setmode, we can use the return value from fg_getmode and again
  165. call fg_setmode before the program exits.
  166.  
  167.      You also can use another Fastgraph routine, fg_bestmode, to determine if
  168. a video mode with a specific resolution is available on the user's system.
  169. The fg_bestmode routine requires three integer arguments:  a horizontal
  170. resolution, a vertical resolution, and the number of video pages required.
  171. As its function value, fg_bestmode returns the video mode number that offers
  172. the most capabilities for the resolution and number of pages requested.  It
  173. returns a value of -1 if no available video mode offers the requested
  174. criteria.
  175.  
  176.      For example, if we require an 80 by 25 text mode, we can use the
  177. function call fg_bestmode(80,25,1) to pick the "best" video mode available
  178. that offers this capability.  In text modes, the term best means to give
  179. preference to a color text mode over a monochrome text mode.  Example 3-4
  180. performs the same function as example 3-3, but it uses fg_bestmode rather
  181. than fg_testmode.
  182.  
  183.                                  Example 3-4.
  184.  
  185.                    #include <fastgraf.h>
  186.                            Chapter 3:  Initializing the Video Environment   47
  187.  
  188.  
  189.                    #include <stdio.h>
  190.                    #include <stdlib.h>
  191.                    void main(void);
  192.  
  193.                    void main()
  194.                    {
  195.                       int old_mode;
  196.                       int new_mode;
  197.  
  198.                       old_mode = fg_getmode();
  199.                       new_mode = fg_bestmode(80,25,1);
  200.  
  201.                       if (new_mode < 0) {
  202.                          printf("This program requires\n");
  203.                          printf("an 80-column display.\n");
  204.                          exit(1);
  205.                          }
  206.  
  207.                       fg_setmode(new_mode);
  208.                       fg_cursor(0);
  209.  
  210.                       fg_setcolor(15);
  211.                       fg_text("Hello, world.",13);
  212.                       fg_waitkey();
  213.  
  214.                       fg_setmode(old_mode);
  215.                       fg_reset();
  216.                    }
  217.  
  218.  
  219. 43-line and 50-line Text Modes
  220.  
  221.      When using an 80-column text mode on a system equipped with an EGA, VGA,
  222. MCGA, or SVGA video display and adapter, you can extend the screen size from
  223. 25 lines to 43 or 50 lines.  While all systems offer 25-line text modes, EGA
  224. systems also offer 43-line modes, MCGA systems also offer 50-line modes, and
  225. VGA and SVGA systems offer both 43-line and 50-line modes.  The 43-line mode
  226. is not available on EGA systems equipped with an RGB display.  If you extend
  227. the screen size to 43 or 50 lines, the physical character size is reduced
  228. proportionally so all lines appear on the screen.
  229.  
  230.      The fg_setlines routine defines the number of text rows per screen.  It
  231. has a single integer argument whose value must be 25, 43, or 50.  If you pass
  232. any other value to fg_setlines, or pass a value not supported by the host
  233. system's video configuration, fg_setlines does nothing.  In addition, calling
  234. fg_setlines makes the text cursor visible.  Another Fastgraph routine,
  235. fg_getlines, returns as its function value the number of text rows currently
  236. in effect.  You also can use fg_getlines in graphics video modes.
  237.  
  238.      Example 3-5 illustrates the use of the fg_setlines and fg_getlines
  239. routines.  The program first establishes the 80-column color text mode (this
  240. sets the screen size to its 25-line default) and makes the text cursor
  241. invisible.  It then displays the words "first line" in the upper left corner
  242. of the screen.  Next, the program checks if an EGA with enhanced display is
  243. available, and if so, changes the screen to 43 lines (video mode 16 is only
  244. available on EGA systems equipped with an enhanced display).  Next, the
  245. 48   Fastgraph User's Guide
  246.  
  247.  
  248. program checks if a VGA, MCGA, or SVGA is available, and if so changes the
  249. screen to 50 lines (video mode 17 is only available on these systems).
  250. Finally, the program restores the original video mode, restores the number of
  251. lines per screen to its original setting, and restores the original screen
  252. attributes before exiting.
  253.  
  254.                                  Example 3-5.
  255.  
  256.                         #include <fastgraf.h>
  257.                         void main(void);
  258.  
  259.                         void main()
  260.                         {
  261.                            int lines;
  262.                            int old_lines;
  263.                            int old_mode;
  264.  
  265.                            old_lines = fg_getlines();
  266.                            old_mode = fg_getmode();
  267.                            fg_setmode(3);
  268.                            fg_cursor(0);
  269.  
  270.                            fg_setcolor(15);
  271.                            fg_text("first line",10);
  272.                            fg_waitkey();
  273.  
  274.                            if (fg_testmode(16,0)) {
  275.                               fg_setlines(43);
  276.                               fg_cursor(0);
  277.                               fg_waitkey();
  278.                               }
  279.  
  280.                            if (fg_testmode(17,0)) {
  281.                               fg_setlines(50);
  282.                               fg_cursor(0);
  283.                               fg_waitkey();
  284.                               }
  285.  
  286.                            fg_setmode(old_mode);
  287.                            fg_setlines(old_lines);
  288.                            fg_reset();
  289.                         }
  290.  
  291.  
  292.  
  293. Establishing a Graphics Mode
  294.  
  295.      The steps for establishing a graphics mode are similar to establishing a
  296. text mode.  However, there are more restrictions since some systems may not
  297. support all the graphics video modes.  For example, a program could not run
  298. in mode 13 on a CGA system, nor could a program run in mode 9 on anything
  299. except a Tandy 1000 or PCjr system.
  300.  
  301.      For graphics programs, it may suffice to write a program to run in a
  302. specific video mode, but it is often more desirable to write a program that
  303. will run in any of several video modes.  This is especially true for
  304.                            Chapter 3:  Initializing the Video Environment   49
  305.  
  306.  
  307. commercial products, since they should ideally run on as many different video
  308. configurations as possible.
  309.  
  310.      Fastgraph includes a routine named fg_automode that determines the
  311. graphics video mode that offers the most functionality for the user's video
  312. hardware configuration.  For example, the Tandy 1000 series computers support
  313. all three CGA modes (4, 5, and 6) and the 320 by 200 16-color Tandy 1000 mode
  314. (9).  Of these modes, mode 9 offers the most features from a graphics
  315. standpoint, so fg_automode will return a value of 9 when run on a Tandy 1000
  316. computer.  The following table summarizes the video mode numbers returned by
  317. fg_automode for given adapter-display combinations.
  318.  
  319.                                          display
  320.                        adapter   mono   RGB   ECD   VGA
  321.  
  322.                           MDA       7     0     7     7
  323.                           HGC      11     0     0    11
  324.                           CGA       0     4     0     0
  325.                           EGA      15    13    16     0
  326.                           VGA      17    17    17    18
  327.                          MCGA      17    17    17    19
  328.                         Tandy       7     9     0     0
  329.                          PCjr       7     9     0     0
  330.  
  331.      Example 3-6 shows how to use fg_automode to determine the "best"
  332. graphics mode for the user's video hardware.  In graphics modes, the term
  333. best means the highest resolution, followed by the number of available
  334. colors.  To maintain compatibility with earlier versions of Fastgraph,
  335. fg_automode does not consider the extended VGA graphics modes (modes 20 to
  336. 23) or SVGA graphics modes (modes 24 to 29) when selecting a video mode.  The
  337. program displays a message that includes the selected video mode number.
  338.  
  339.                                  Example 3-6.
  340.  
  341.                     #include <fastgraf.h>
  342.                     #include <stdio.h>
  343.                     void main(void);
  344.  
  345.                     void main()
  346.                     {
  347.                        int old_mode;
  348.                        int new_mode;
  349.                        char string[4];
  350.  
  351.                        old_mode = fg_getmode();
  352.                        new_mode = fg_automode();
  353.                        fg_setmode(new_mode);
  354.  
  355.                        fg_setcolor(15);
  356.                        fg_text("I'm running in mode ",20);
  357.                        sprintf(string,"%d.",new_mode);
  358.                        fg_text(string,3);
  359.                        fg_waitkey();
  360.  
  361.                        fg_setmode(old_mode);
  362.  
  363. 50   Fastgraph User's Guide
  364.  
  365.  
  366.                        fg_reset();
  367.                     }
  368.  
  369.  
  370.      For simple programs such as example 3-6, different screen resolutions
  371. may not be an issue.  However, in more complex graphics programs it is often
  372. desirable to write a program for a fixed screen resolution.  A common
  373. practice is to develop graphics programs to run in modes 4 (for CGA), 9
  374. (Tandy 1000 or PCjr), 12 (Hercules), 13 (EGA, VGA, or SVGA), and 19 or 20
  375. (MCGA, VGA, or SVGA).  The reason for selecting these five modes is they all
  376. use the same 320 by 200 resolution and will run on any IBM PC or PS/2 with
  377. graphics capabilities.
  378.  
  379.      Example 3-7 performs the same function as example 3-6, but it uses
  380. fg_bestmode instead of fg_automode to restrict the program to 320 by 200
  381. graphics modes.  For this resolution, the fg_bestmode routine will first
  382. check the availability of mode 20, followed by modes 19, 13, 9, 4, and 12.
  383. If fg_bestmode determines no 320 by 200 graphics mode is available (indicated
  384. by a return value of -1), the program prints an informational message and
  385. exits.  Otherwise it selects the video mode fg_bestmode proposes and
  386. continues.
  387.  
  388.                                  Example 3-7.
  389.  
  390.      #include <fastgraf.h>
  391.      #include <stdio.h>
  392.      #include <stdlib.h>
  393.      void main(void);
  394.  
  395.      void main()
  396.      {
  397.         int old_mode;
  398.         int new_mode;
  399.         char string[4];
  400.  
  401.         old_mode = fg_getmode();
  402.         new_mode = fg_bestmode(320,200,1);
  403.  
  404.         if (new_mode < 0) {
  405.            printf("This program requires a 320 by 200 graphics mode.\n");
  406.            exit(1);
  407.            }
  408.  
  409.         fg_setmode(new_mode);
  410.  
  411.         fg_setcolor(15);
  412.         fg_text("I'm running in mode ",20);
  413.         sprintf(string,"%d.",new_mode);
  414.         fg_text(string,3);
  415.         fg_waitkey();
  416.  
  417.         fg_setmode(old_mode);
  418.         fg_reset();
  419.      }
  420.  
  421.                            Chapter 3:  Initializing the Video Environment   51
  422.  
  423.  
  424.      If a program will run in specific video modes, you may want to consider
  425. using the fg_testmode routine instead of fg_bestmode to check for
  426. availability of these video modes.  You also may want to use fg_testmode to
  427. change the video mode precedence used by fg_bestmode.  For example, mode 13
  428. (EGA) is faster than mode 19 (MCGA), so you may want to consider giving EGA
  429. precedence over MCGA, especially if your program does not use more than 16
  430. colors.
  431.  
  432.      Example 3-8 is similar to example 3-7, but it will only run in the 320
  433. by 200 EGA, MCGA, and CGA graphics modes (video modes 13, 19, and 4,
  434. respectively).  The program uses fg_testmode to select its video mode.  Note
  435. the order of calls to fg_testmode gives EGA precedence over MCGA, and MCGA
  436. precedence over CGA.
  437.  
  438.                                  Example 3-8.
  439.  
  440.         #include <fastgraf.h>
  441.         #include <stdio.h>
  442.         #include <stdlib.h>
  443.         void main(void);
  444.  
  445.         void main()
  446.         {
  447.            int old_mode;
  448.            char string[4];
  449.  
  450.            old_mode = fg_getmode();
  451.  
  452.            if (fg_testmode(13,1))
  453.               fg_setmode(13);
  454.            else if (fg_testmode(19,1))
  455.               fg_setmode(19);
  456.            else if (fg_testmode(4,1))
  457.               fg_setmode(4);
  458.            else {
  459.               printf("This program requires an EGA, MCGA, or CGA.\n");
  460.               exit(1);
  461.               }
  462.  
  463.            fg_setcolor(15);
  464.            fg_text("I'm running in mode ",20);
  465.            sprintf(string,"%d.",getmode());
  466.            fg_text(string,3);
  467.            fg_waitkey();
  468.  
  469.            fg_setmode(old_mode);
  470.            fg_reset();
  471.         }
  472.  
  473.  
  474. SuperVGA Graphics Modes
  475.  
  476.      Unlike previous generations of graphics cards, there was no video
  477. standard in place when different companies began developing SVGA cards.  As
  478. a result, they implemented enhanced SVGA features according to their own
  479. specifications based upon different video controller chips.  Each such
  480. 52   Fastgraph User's Guide
  481.  
  482. implementation is called a chipset.  While each chipset generally offers the
  483. same video memory organization and common screen resolutions, the SVGA-
  484. specific features such as mode initialization, bank switching, and setting
  485. the display start address differ radically between chipsets.  In other words,
  486. code written for one specific SVGA chipset will not run on another chipset,
  487. even at the same resolution.  This is why many software vendors provide
  488. different SVGA drivers for their products.
  489.  
  490.      Fastgraph's integrated SVGA kernel makes these obscure differences
  491. between SVGA chipsets transparent, without the need for external drivers.
  492. This means, for instance, if you write an application for the 1024 by 768
  493. 256-color SVGA graphics mode, it will run without changes on any supported
  494. SVGA chipset which offers that resolution.  The SVGA kernel supports the
  495. chipsets listed in the table below.  A "Y" entry means the chipset supports
  496. the video mode, and an "N" means it doesn't.  The last two rows of the table
  497. show the amount of video memory required to support each mode and Fastgraph's
  498. corresponding video mode numbers.
  499.  
  500.                     ----------- 256 colors -----------  -- 16 colors ---
  501. SVGA chipset        640x400  640x480  800x600 1024x768  800x600 1024x768
  502.  
  503. Ahead "A" type         Y        Y        Y        N        Y        Y
  504. Ahead "B" type         Y        Y        Y        Y        Y        Y
  505. ATI 18800              Y        Y        Y        N        Y        N
  506. ATI 18800-1            Y        Y        Y        N        Y        Y
  507. ATI 28800              Y        Y        Y        Y        Y        Y
  508. Chips&Tech 82c451      Y        N        N        N        Y        N
  509. Chips&Tech 82c452      Y        Y        N        N        Y        Y
  510. Chips&Tech 82c453      Y        Y        Y        Y        Y        Y
  511. Cirrus Logic 54xx      N        Y        Y        Y        Y        Y
  512. Genoa 6000 series      Y        Y        Y        N        Y        Y
  513. Oak OTI-067            N        Y        Y        N        Y        Y
  514. Paradise PVGA1a        Y        Y        N        N        Y        N
  515. Paradise WD90C00/10    Y        Y        N        N        Y        Y
  516. Paradise WD90C11/30/31 Y        Y        Y        Y        Y        Y
  517. S3                     N        Y        Y        Y        Y        Y
  518. Trident 8800           Y        Y        N        N        Y        Y
  519. Trident 8900/9000      Y        Y        Y        Y        Y        Y
  520. Tseng ET3000           N        Y        Y        N        Y        Y
  521. Tseng ET4000           Y        Y        Y        Y        Y        Y
  522. Video7                 Y        Y        Y        Y        Y        Y
  523.  
  524. minimum video RAM     256K     512K     512K     1MB      256K     512K
  525. Fastgraph mode number  24       25       26       27       28       29
  526.  
  527. The SVGA kernel maps Fastgraph's video mode numbers (24 to 29) to the
  528. chipset-specific mode numbers.  For example, the 640 by 480 256-color SVGA
  529. mode is 62 hex on an ATI card, 5D hex on a Trident card, and 2E hex on a
  530. Tseng card, but it's always mode 25 from Fastgraph's perspective.
  531.  
  532.      The Video Electronics Standards Association (VESA) has assumed the
  533. complex task of improving software compatibility of SVGA cards from different
  534. companies.  Most SVGA cards sold today include VESA compatibility, either
  535. directly in ROM or through loadable software drivers supplied with the card.
  536. Besides supporting specific chipsets, Fastgraph's SVGA kernel supports any
  537. SVGA card with VESA compatibility.  Note that VESA is not a chipset, but a
  538. BIOS-level interface between an application (the SVGA kernel in this case)
  539.                            Chapter 3:  Initializing the Video Environment   53
  540.  
  541. and chipset-specific functions.  While the current VESA standard covers all
  542. six SVGA graphics modes that Fastgraph supports, these modes are only
  543. available if the underlying chipset also supports them.
  544.  
  545.      When using VESA compatibility, the VESA BIOS handles all chipset-
  546. specific functions such as bank switching.  The overhead imposed by the BIOS
  547. usually makes the VESA modes slightly slower than using chipset-specific
  548. functions directly.  For this reason, you can specify if you want to give
  549. precedence to the chipset-specific code or to the VESA BIOS.  Chipset-
  550. specific precedence means the SVGA kernel will only use the VESA BIOS if no
  551. supported SVGA chipset is found.  Conversely, VESA precedence means the
  552. kernel will only use the chipset-specific functions if no VESA BIOS is found.
  553.  
  554.      Before you use any SVGA graphics mode, you must use the fg_svgainit
  555. routine to initialize the SVGA kernel (fg_svgainit must be called before
  556. fg_setmode, fg_bestmode, or fg_testmode).  There are three ways to initialize
  557. the SVGA kernel with fg_svgainit:
  558.  
  559.         - autodetect the user's SVGA chipset, giving precedence to
  560.           chipset-specific code
  561.         - autodetect the user's SVGA chipset, giving precedence to
  562.           the VESA BIOS
  563.         - use a designated SVGA chipset
  564.  
  565. The fg_svgainit routine's argument is an integer value between 0 and 19 that
  566. specifies which initialization method to use.  Passing 0 to fg_svgainit uses
  567. the first method, in which the SVGA kernel searches for all supported
  568. chipsets before checking if a VESA BIOS is present.  This means the SVGA
  569. kernel will only use VESA functions if fg_svgainit doesn't find one of the
  570. supported chipsets.  Passing 1 to fg_svgainit also performs a chipset
  571. autodetect, but in this case the SVGA kernel first searches for a VESA BIOS,
  572. then through the list of supported chipsets.  This means chipset-specific
  573. code will be used only when no VESA BIOS is found.  You can also initialize
  574. the SVGA kernel for a specific chipset by passing a value between 2 and 19 to
  575. fg_svgainit.  The following table summarizes the fg_svgainit initialization
  576. codes.
  577.  
  578.                   code   chipset
  579.  
  580.                     0    autodetect (with chipset-specific precedence)
  581.                     1    autodetect (with VESA precedence)
  582.                     2    Ahead "A" type
  583.                     3    Ahead "B" type
  584.                     4    ATI 18800
  585.                     5    ATI 18800-1
  586.                     6    ATI 28800
  587.                     7    Chips & Technologies 82c451/455/456
  588.                     8    Chips & Technologies 82c452
  589.                     9    Chips & Technologies 82c453
  590.                    10    Genoa 6000 series
  591.                    11    Oak OTI-067
  592.                    12    Paradise PVGA1a
  593.                    13    Paradise WD90C00/WD90C10
  594.                    14    Paradise WD90C11/WD90C30/WD90C31
  595.                    15    Trident 8800
  596.                    16    Trident 8900
  597.                    17    Tseng ET3000
  598. 54   Fastgraph User's Guide
  599.  
  600.                    18    Tseng ET4000
  601.                    19    Video7
  602.                    20    Cirrus Logic 5400 series
  603.                    21    S3
  604.                    22    Trident 8900B/8900C/9000
  605.  
  606.      For autodetect requests, fg_svgainit returns a value between 1 and 19
  607. corresponding to the SVGA chipset found.  If the return value is 1, it means
  608. a VESA BIOS will be used.  A value between 2 and 22 means a specific SVGA
  609. chipset (as listed in the preceding table) will be used.  If no VESA BIOS or
  610. supported SVGA chipset is found, fg_svgainit returns zero.  In this case,
  611. Fastgraph's SVGA graphics modes are not available.
  612.  
  613.      When you request initialization for a specific chipset, fg_svgainit
  614. always returns the value passed to it.  It does not check if that chipset is
  615. actually present, so this feature should be used judiciously.
  616.  
  617.      Example 3-9 is a simple program that checks if an SVGA card is present,
  618. and if so, displays the name of the SVGA chipset.  It also displays how much
  619. video memory is present on the SVGA card and the version number of
  620. Fastgraph's SVGA kernel.
  621.  
  622.                                  Example 3-9.
  623.  
  624.            #include <fastgraf.h>
  625.            #include <stdio.h>
  626.            void main(void);
  627.  
  628.            char *description[] =
  629.            {
  630.               "cannot be determined",
  631.               "VESA",
  632.               "Ahead A",
  633.               "Ahead B",
  634.               "ATI 18800",
  635.               "ATI 18800-1",
  636.               "ATI 28800",
  637.               "Chips & Technologies 82c451/455/456",
  638.               "Chips & Technologies 82c452",
  639.               "Chips & Technologies 82c453",
  640.               "Genoa 6000 series",
  641.               "Oak OTI-067",
  642.               "Paradise PVGA1a",
  643.               "Paradise WD90C00/WD90C10",
  644.               "Paradise WD90C11/WD90C30/WD90C31",
  645.               "Trident 8800",
  646.               "Trident 8900",
  647.               "Tseng ET3000",
  648.               "Tseng ET4000",
  649.               "Video7",
  650.               " ",
  651.               "S3",
  652.               "Trident 8900B/8900C/9000"
  653.            };
  654.  
  655.            void main()
  656.            {
  657.                            Chapter 3:  Initializing the Video Environment   55
  658.  
  659.               int id, major, minor;
  660.  
  661.               id = fg_svgainit(0);
  662.               printf("SVGA chipset:  %s\n",description[id]);
  663.               printf("video memory:  %d kilobytes\n",fg_memory());
  664.               fg_svgaver(&major,&minor);
  665.               printf("SVGA version:  %d.%2.2d\n",major,minor);
  666.            }
  667.  
  668. This example uses fg_svgainit to automatically detect the user's SVGA
  669. chipset.  It initializes the SVGA kernel so that chipset-specific code is
  670. given precedence over VESA (passing 1 instead of 0 to fg_svgainit would give
  671. VESA precedence).  Note that the program does not establish an SVGA graphics
  672. mode -- it just uses the fg_svgainit return value to identify which chipset
  673. is present.
  674.  
  675.      Example 3-9 also includes two other Fastgraph routines relevant to the
  676. SVGA kernel.  The fg_memory function returns the amount of video memory (in
  677. kilobytes) resident on the user's video card.  For example, the fg_memory
  678. return value is 1,024 for a 1MB SVGA card.  Another routine, fg_svgaver,
  679. returns the major and minor numbers for the SVGA kernel, similar to the
  680. fg_version routine mentioned in Chapter 1.  Note that the SVGA kernel version
  681. number is not the same as the Fastgraph version number.
  682.  
  683.      Our next example, 3-10, is an SVGA version of example 3-8.  This program
  684. initializes the SVGA kernel so that VESA will have precedence over chipset-
  685. specific code.  It then calls fg_testmode to find a supported 256-color SVGA
  686. graphics mode, first trying mode 27 (1024 by 768), then mode 26 (800 by 600),
  687. and finally mode 25 (640 by 480).  Checking the modes in this sequence
  688. insures the program will use the highest resolution available, given the
  689. user's SVGA chipset (not all chipsets support all resolutions) and the amount
  690. of video memory present (mode 27 requires 1MB video RAM; modes 26 and 25 need
  691. 512K).
  692.  
  693.      If all three fg_testmode calls fail in example 3-10, the program
  694. displays an appropriate message and exits.  This would happen if the program
  695. were run on a non-SVGA system, run on an unsupported SVGA chipset without
  696. VESA compatibility, or if the SVGA card does not have at least 512K video
  697. memory (modes 25, 26, and 27 all require at least 512K).  In the first two
  698. cases, the fg_svgainit function wouldn't be able to initialize the SVGA
  699. kernel, so fg_testmode would fail when checking the availability of any SVGA
  700. graphics mode.  That's why it's not necessary to check the fg_svgainit return
  701. value in this case.
  702.  
  703.                                 Example 3-10.
  704.  
  705.              #include <fastgraf.h>
  706.              #include <stdio.h>
  707.              #include <stdlib.h>
  708.              void main(void);
  709.  
  710.              void main()
  711.              {
  712.                 int old_mode;
  713.                 char string[4];
  714.  
  715.                 old_mode = fg_getmode();
  716. 56   Fastgraph User's Guide
  717.  
  718.  
  719.                 fg_svgainit(1);
  720.  
  721.                 if (fg_testmode(27,1))
  722.                    fg_setmode(27);
  723.                 else if (fg_testmode(26,1))
  724.                    fg_setmode(26);
  725.                 else if (fg_testmode(25,1))
  726.                    fg_setmode(25);
  727.                 else {
  728.                    printf("This program requires an SVGA\n");
  729.                    printf("with at least 512K video memory.\n");
  730.                    exit(1);
  731.                    }
  732.  
  733.                 fg_setcolor(15);
  734.                 fg_text("I'm running in mode ",20);
  735.                 sprintf(string,"%d.",fg_getmode());
  736.                 fg_text(string,3);
  737.                 fg_waitkey();
  738.  
  739.                 fg_setmode(old_mode);
  740.                 fg_reset();
  741.              }
  742.  
  743.      Some third party SVGA cards based on Fastgraph's supported chipsets do
  744. not completely follow the chipset manufacturer's recommended video mode
  745. numbers and register definitions.  While the SVGA kernel tries to compensate
  746. for these problems when known, it's just not possible to support every
  747. problematic SVGA card.  For this reason, we recommend SVGA applications that
  748. give precedence to chipset-specific code also provide a way to select VESA
  749. compatibility, such as through a command line switch or configuration file.
  750. The VESA driver supplied with a problem card should work around these
  751. incompatibilities.  If it doesn't, you can be assured that most (if not all)
  752. SVGA applications will fail on that card, whether or not they were written
  753. with Fastgraph.
  754.  
  755.      Another important point to consider when writing SVGA applications is
  756. the compatibility between the video card and monitor.  Virtually all SVGA
  757. monitors made today have no problems supporting the bandwidth required by any
  758. of Fastgraph's SVGA graphics modes.  However, some monitors (most notably
  759. older multisync monitors) cannot support the higher resolution modes such as
  760. 800 by 600 and 1024 by 768.  The SVGA kernel checks if the SVGA card supports
  761. the requested resolution, but it does not check if the card/monitor
  762. combination does.
  763.  
  764.  
  765. Summary of Video Initialization Routines
  766.  
  767.      This section summarizes the functional descriptions of the Fastgraph
  768. routines presented in this chapter.  More detailed information about these
  769. routines, including their arguments and return values, may be found in the
  770. Fastgraph Reference Manual.
  771.  
  772.      FG_AUTOMODE determines the graphics video mode that offers the most
  773. features for the user's display and adapter configuration.  The value it
  774. returns helps determine a suitable value to pass to the fg_setmode routine.
  775.                            Chapter 3:  Initializing the Video Environment   57
  776.  
  777.  
  778.  
  779.      FG_BESTMODE is similar to fg_automode, but it excludes video modes that
  780. do not offer the specified resolution and video page requirements.
  781.  
  782.      FG_CURSOR makes the text mode cursor visible or invisible.  This routine
  783. has no effect when used in a graphics mode.
  784.  
  785.      FG_GETLINES returns the number of text rows per screen for the current
  786. video mode.
  787.  
  788.      FG_GETMODE returns the current video mode.  It is typically one of the
  789. first Fastgraph routines called in a program.  The value returned by
  790. fg_getmode can be retained to restore the original video mode when a program
  791. transfers control back to DOS.
  792.  
  793.      FG_MEMORY returns the amount of video memory present (in kilobytes) on
  794. the user's SVGA card.  This routine is meaningful only after successfully
  795. initializing the SVGA kernel with fg_svgainit.
  796.  
  797.      FG_RESET is generally the last Fastgraph routine called in a program.
  798. It only functions in text video modes.  When the ANSI.SYS driver is not
  799. loaded, fg_reset merely erases the screen.  When ANSI.SYS is loaded, fg_reset
  800. also restores any previously set screen attributes.
  801.  
  802.      FG_SETLINES extends an 80-column text mode to 25, 43, or 50 lines per
  803. screen.  This routine is only meaningful when running in 80-column text modes
  804. on EGA, VGA, or MCGA systems (in other cases it does nothing).
  805.  
  806.      FG_SETMODE establishes a video mode and initializes Fastgraph's internal
  807. parameters for that video mode.  It must be called before any Fastgraph
  808. routine that performs video output.  A program can call fg_setmode as many
  809. times as needed to switch between different video modes.
  810.  
  811.      FG_SVGAINIT initializes Fastgraph's SVGA kernel and performs chipset-
  812. specific SVGA initialization.  This routine must be called before
  813. establishing an SVGA graphics mode with fg_setmode.
  814.  
  815.      FG_SVGAVER returns the Fastgraph SVGA kernel major and minor version
  816. numbers.
  817.  
  818.      FG_TESTMODE determines whether or not a specified video mode (with a
  819. given number of video pages) is available on the user's system.
  820. 58   Fastgraph User's Guide
  821.